/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-09-06
 * Time: 23:09
 */
public class Test91 {
    public static void main(String[] args) {
        int[] num = {1,5,11,5};
        boolean ret = canPartition(num);
        System.out.println(ret);
    }
    public static boolean canPartition(int[] nums) {
        int sum  = 0;
        int n = nums.length;
        for(int x : nums) {
            sum += x;
        }

        if(sum % 2 == 1) {
            return false;
        }
        int target = sum/2;

        boolean[] dp = new boolean[target+1];
        dp[0] = true;

        for(int i = 1; i < n; i++) {
            for(int j = target; j >= nums[i-1]; j--) {
                dp[j] = dp[j] || dp[j-nums[i-1]];
            }
        }
        return dp[target];
    }
}
